package cn.skyquant.quant4j.service.boot.model.sms;

/**
 * Created by harley-dog on 2016/4/24.
 */

import cn.skyquant.quant4j.sdk.util.string.StringUtils;
import com.alibaba.fastjson.JSONObject;
import org.springframework.util.CollectionUtils;

import java.util.Collection;
import java.util.Map;

/**
 * 短信实体
 */
public class SMS {
    public Collection<String> recTelSet;    //接受者手机号集合
    public String templateCode;     //短信模版码
    public String signName;           //短信签名
    public Map<String,String> params;//变量替换

    public SMS(Collection<String> recTelSet, String templateCode, String signName, Map<String, String> params) {
        this.recTelSet = recTelSet;
        this.templateCode = templateCode;
        this.signName = signName;
        this.params = params;
    }

    public String getTelNumStr(){
        if(CollectionUtils.isEmpty(recTelSet)){
            return null;
        }else{
            return StringUtils.join(recTelSet,"","");
        }
    }

    public String getTemplateParam(){
        if(CollectionUtils.isEmpty(params)){
            return null;
        }else{
            return JSONObject.toJSONString(params);
        }
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        SMS sms = (SMS) o;

        if (recTelSet != null ? !recTelSet.equals(sms.recTelSet) : sms.recTelSet != null) return false;
        if (templateCode != null ? !templateCode.equals(sms.templateCode) : sms.templateCode != null) return false;
        if (signName != null ? !signName.equals(sms.signName) : sms.signName != null) return false;
        return params != null ? params.equals(sms.params) : sms.params == null;

    }

    @Override
    public int hashCode() {
        int result = recTelSet != null ? recTelSet.hashCode() : 0;
        result = 31 * result + (templateCode != null ? templateCode.hashCode() : 0);
        result = 31 * result + (signName != null ? signName.hashCode() : 0);
        result = 31 * result + (params != null ? params.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "SMS{" +
                "recTelSet=" + recTelSet +
                ", templateCode='" + templateCode + '\'' +
                ", signName='" + signName + '\'' +
                ", params=" + params +
                '}';
    }
}
